package 地牢大师;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
    static int N = 110, L, R, C;
    static char[][][] g = new char[N][N][N];
    static int[][][] st = new int[N][N][N];
    static int[] dx = new int[]{1, -1, 0, 0, 0, 0};
    static int[] dy = new int[]{0, 0, 1, -1, 0, 0};
    static int[] dz = new int[]{0, 0, 0, 0, 1, -1};

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (true) {
            L = in.nextInt();
            R = in.nextInt();
            C = in.nextInt();
            if (L == 0 && R == 0 && C == 0) {
                break;
            }
            PIII start = null;
            for (int i = 0; i < L; i++) {
                for (int j = 0; j < R; j++) {
                    g[i][j] = in.next().toCharArray();
                    for (int k = 0; k < C; k++) {
                        if (g[i][j][k] == 'S') {
                            start = new PIII(i, j, k);
                            break;
                        }
                    }
                }
            }
            int res = bfs(start);
            if (res == -1) {
                System.out.println("Trapped!");
            } else {
                System.out.printf("Escaped in %d minute(s).\n", res);
            }
        }
    }

    private static int bfs(PIII start) {
        Queue<PIII> q = new LinkedList<>();
        q.offer(start);
        for (int i = 0; i < L; i++) {
            for (int j = 0; j < R; j++) {
                Arrays.fill(st[i][j], -1);
            }
        }
        st[start.x][start.y][start.z] = 0;
        while (!q.isEmpty()) {
            PIII t = q.poll();
            for (int i = 0; i < 6; i++) {
                int a = dx[i] + t.x;
                int b = dy[i] + t.y;
                int c = dz[i] + t.z;
                if (a < 0 || a >= L || b < 0 || b >= R || c < 0 || c >= C) {
                    continue;
                }
                if (st[a][b][c] != -1) {
                    continue;
                }
                if (g[a][b][c] == '#') {
                    continue;
                }
                st[a][b][c] = st[t.x][t.y][t.z] + 1;
                if (g[a][b][c] == 'E') {
                    return st[a][b][c];
                }
                q.offer(new PIII(a, b, c));
            }
        }
        return -1;
    }
}

class PIII {
    int x, y, z;

    public PIII(int x, int y, int z) {
        this.x = x;
        this.y = y;
        this.z = z;
    }
}
